from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
from django.utils import timezone


class UserProfile(AbstractUser):
    """
       用户
    """
    GENDER_CHOICES = (
        ("male", "男"),
        ("female", "女")
    )
    mobile = models.CharField(verbose_name="手机号码",max_length=11,unique=True,null=True)
    nickname = models.CharField(verbose_name="昵称",max_length=50,null=True,blank=True)
    gender = models.CharField("性别", max_length=6, choices=GENDER_CHOICES,default='female')
    avatar = models.ImageField(upload_to="avatar", verbose_name="用户头像", null=True, blank=True, help_text="用户头像")

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name
        indexes = [
            models.Index(fields=['username'],),
        ]

    def __str__(self):
        return self.username


class UserAddress(models.Model):
    """
    用户收货地址
    """
    user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name="用户",related_name='address' )
    province = models.CharField("省份",max_length=100, default="")
    city = models.CharField("城市",max_length=100, default="")
    district = models.CharField("区域",max_length=100, default="")
    address = models.CharField("详细地址",max_length=100, default="")
    signer_name = models.CharField("签收人",max_length=100, default="")
    signer_mobile = models.CharField("电话",max_length=11, default="")
    isdefault = models.BooleanField("是否默认",default=False)
    add_time = models.DateTimeField("添加时间",default=timezone.now)

    class Meta:
        verbose_name = "收货地址"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.address
